package com.cn.wanxi.servlet;

import com.cn.wanxi.model.AdvertisingModel;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.AdvertisingService;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        /////////////////////////////////////////////////////////////////导航部分广告
        //导航会有六个不同的对象，然后一起发送到前端页面
        NavService navService = new NavService();
        ArrayList<NavModel> navModelList = navService.getNavModelListForHome();
        req.setAttribute("navModelList",navModelList);
        //java 的四大作用域
        //////////////////////////////////////////////////////////////公司信息
        CompanyService companyService = new CompanyService();
        CompanyModel companyModel = companyService.getCompanyModel();
        req.setAttribute("company",companyModel);
        //////////////////////////////////////////////////////////////勤奋 · 求实 · 进取 · 创造部分广告
        AdvertisingService advertisingService = new AdvertisingService();
        AdvertisingModel advertisingModel= advertisingService.getAdvertisingModel();
        req.setAttribute("advertising",advertisingModel);
        //////////////////////////////////////////////////////////////中间辅导班导航
        ArrayList<NavModel> navModelList2 = navService.getNavModelListForHome();
        for(int i = 0 ; i < navModelList2.size() ; i++) {
            if(i==3){
                String href = navModelList2.get(i).getHref();
                req.setAttribute("navModelList2",href);
                break;
            }
        }

        /////////////////////////////////////////////////////////////中间我们的服务优势部分
        AdvertisingModel advertisingModel2=advertisingService.getTwoAdvertisingModel();
        req.setAttribute("twoAdvertising",advertisingModel2);
        ////////////////////////////////////////////////////////////中间关于我们部分
        CompanyModel companyModel2 = companyService.getCompanyModel2();
        req.setAttribute("company2",companyModel2);
        ////////////////////////////////////////////////////////////中间公司理念部分
        CompanyModel companyModel3 = companyService.getCompanyModelIdea();
        req.setAttribute("company3",companyModel3);
        ///////////////////////////////////////////////////////////中间部分联系我们
        CompanyModel companyModel4 = companyService.getCompanyModelContactDetails();
        req.setAttribute("company4",companyModel4);
        ///////////////////////////////////////////////////////////底部公司信息
        CompanyModel companyModel5 = companyService.getCompanyModelbottom();
        req.setAttribute("company5",companyModel5);
        /////////////////////////////////////////////////////////////中间新闻中心部分
        NewsService newsService = new NewsService();
        ArrayList<NewsModel> newsModel= newsService.getNewsModelListForHome();
        req.setAttribute("newsModel",newsModel);


//        数据页面转发
        req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);
    }
}
